//  TPMacros.h
//  Created by wealthgrow on 2020/6/10.
//  Copyright © 2020 qimeng. All rights reserved.

#ifndef TPMacros_h
#define TPMacros_h


#define TKWeakObj(o) autoreleasepool{} __weak typeof(o) o##Weak = o;
#define TKStrongObj(o) autoreleasepool{} __strong typeof(o) o = o##Weak;

//通知
#define TPNotice [NSNotificationCenter defaultCenter]
//TPAPPDelegate
#define TPAPPDelegate [AppDelegate shareDelegate]

#define KEY_WINDOW                 [[[UIApplication sharedApplication]delegate]window]

//系统版本
//系统版本是否是某个版本
#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
//系统版本是否大于某个版本
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
//系统版本是否大于等于某个版本
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
//系统版本是否小于某个版本
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
//系统版本是否小于等于某个版本
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

//大于等于7.0的ios版本
#define iOS7_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")

//大于等于8.0的ios版本
#define iOS8_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")

//大于等于10.0的ios版本
#define iOS10_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")

//weakself
#define WeakSelf(weakSelf)  __weak __typeof(&*self) weakSelf = self;
#define WeakDefine(strongA, weakA) __weak typeof(strongA) weakA = strongA;

#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)

#define SuppressDeclaredSelectorWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wundeclared-selector\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)

#ifdef DEBUG

#define NSLog(format, ...) do { \
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; \
[formatter setDateFormat:@"HH:mm:ss"]; \
NSString *timeStr = [formatter stringFromDate:[NSDate date]]; \
fprintf(stderr, "[%s] %s [第%d行] %s\n", \
[timeStr UTF8String], \
[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], \
__LINE__, \
[[NSString stringWithFormat:format, ##__VA_ARGS__] UTF8String]); \
} while (0);

//#define NSLog(format, ...) printf("%s %s [第%d行] %s\n", [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __FUNCTION__, __LINE__, [[NSString stringWithFormat:format, ## __VA_ARGS__] UTF8String]);

#define debugMethod() NSLog(@"%s", __func__)
#else
#define NSLog(...)
#define debugMethod()
#endif


//获取系统时间戳
//毫秒（13位）
#define CurentTimeMilliSecond [NSString stringWithFormat:@"%lld", (long long)([[NSDate date] timeIntervalSince1970]*1000)]
//秒（10位）
#define CurentTimeSecond [NSString stringWithFormat:@"%lld",(long long)[[NSDate date] timeIntervalSince1970]]

//判断空指针
#define IsNilOrNull(_ref)   (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]))

#endif /* TPMacros_h */
